package com.example.tijianserver.service;

import com.example.tijianserver.mapper.CheckitemMapper;
import com.example.tijianserver.mapper.SetmealMapper;
import com.example.tijianserver.mapper.SetmealdetailedMapper;
import com.example.tijianserver.pojo.Checkitem;
import com.example.tijianserver.pojo.Setmeal;
import com.example.tijianserver.pojo.Setmealdetailed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SetmealSercerImpl implements SetmealService{

    @Autowired
    SetmealMapper setmealMapper;

    @Autowired
    SetmealdetailedMapper setmealdetailedMapper;
    @Autowired
    CheckitemMapper checkitemMapper;

    //查询套餐信息
    @Override
    public List<Setmeal> listByType(Setmeal setmeal) {

        List<Setmeal> setmeals = setmealMapper.selectByType(setmeal.getType());

        for(Setmeal sm:setmeals) {
            Integer smId = sm.getSmId();// 获取套餐编号
            List<Integer> ciIdList = setmealdetailedMapper.selectBySmId(smId);
            List<Checkitem> checkItemList=new ArrayList<>();

            for (Integer ciId:ciIdList){
                Checkitem checkItem=checkitemMapper.selectByPrimaryKey(ciId);
                checkItemList.add(checkItem);

            }
            sm.setCheckItemList(checkItemList);
        }

        return setmeals;
    }

    @Override
    public Setmeal selectByPrimaryKey(Integer smId) {
        return setmealMapper.selectByPrimaryKey(smId);
    }

}
